package com.banmao.mall.controller.admin;

import com.banmao.mall.model.bo.admin.market.BrandListBO;
import com.banmao.mall.model.vo.BaseRespVO;
import com.banmao.mall.model.vo.admin.market.BrandListVO;
import com.banmao.mall.model.vo.admin.market.ProvinceVO;
import com.banmao.mall.model.vo.admin.statistic.*;
import com.banmao.mall.service.admin.MarketService;
import com.banmao.mall.service.admin.StatisticService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/admin")
public class StatisticController {


    @Autowired
    StatisticService statisticService;

    /**
     *1.建立SQL,查找数据
     * 2.封装VO
     * @return
     */
    @RequestMapping("/stat/user")
    @RequiresPermissions("admin:stat:user")
    public BaseRespVO totalNumberOfUsers() {

        List<UserTotalRowsVO> userTotalRowsVOS = statisticService.statisticsUsers();
        UserTotalVO userTotalVO = new UserTotalVO();
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("day");
        arrayList.add("users");
        userTotalVO.setColumns(arrayList);
        userTotalVO.setRows(userTotalRowsVOS);
        return BaseRespVO.ok(userTotalVO, "成功", 0);
    }



    @RequestMapping("/stat/order")
    @RequiresPermissions("admin:stat:order")
    public BaseRespVO totalNumberOfOrders() {
//        1.获取行对象组
//        2.准备列名字符组
//        3.封装OrderTotalVO对象
//        4.封装最终结果
        List<OrderTotalRowsVO> list = statisticService.statisticsOrders();
        OrderTotalVO orderTotalVO = new OrderTotalVO();
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("day");
        arrayList.add("orders");
        arrayList.add("customers");
        arrayList.add("amount");
        arrayList.add("pcr");

        orderTotalVO.setColumns(arrayList);
        orderTotalVO.setRows(list);

        return BaseRespVO.ok(orderTotalVO, "成功", 0);
    }

    @RequestMapping("/stat/goods")
    @RequiresPermissions("admin:stat:goods")
    public BaseRespVO totalNumberOfGoods() {

//        1.获取行对象组
//        2.准备列名字符组
//        3.封装OrderTotalVO对象
//        4.封装最终结果
        List<GoodsTotalRowsVO> list = statisticService.statisticsGoods();
        GoodsTotalVO goodsTotalVO = new GoodsTotalVO();
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("day");
        arrayList.add("orders");
        arrayList.add("products");
        arrayList.add("amount");

        goodsTotalVO.setColumns(arrayList);
        goodsTotalVO.setRows(list);

        return BaseRespVO.ok(goodsTotalVO, "成功", 0);
    }

}
